@meowdown/core 0.5.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -15,14 +15,14 @@ The editor extension binds inline-format toggles (`Mod` = Cmd on macOS, Ctrl els
15
15
 
16
16
  Heading shortcuts toggle the current block to a heading of that level (or back to a paragraph):
17
17
 
18
- | Key | Action |
19
- | --------------------- | --------- |
20
- | `Mod-1` / `Mod-Alt-1` | Heading 1 |
21
- | `Mod-2` / `Mod-Alt-2` | Heading 2 |
22
- | `Mod-3` / `Mod-Alt-3` | Heading 3 |
23
- | `Mod-4` / `Mod-Alt-4` | Heading 4 |
24
- | `Mod-5` / `Mod-Alt-5` | Heading 5 |
25
- | `Mod-6` / `Mod-Alt-6` | Heading 6 |
18
+ | Key | Action |
19
+ | ------- | --------- |
20
+ | `Mod-1` | Heading 1 |
21
+ | `Mod-2` | Heading 2 |
22
+ | `Mod-3` | Heading 3 |
23
+ | `Mod-4` | Heading 4 |
24
+ | `Mod-5` | Heading 5 |
25
+ | `Mod-6` | Heading 6 |
26
26
 
27
27
  `EDITOR_KEY_BINDINGS` is a literal (`as const`) object mapping every key above to its description, for host settings UIs and keybinding-collision checks.
28
28
 
package/dist/index.d.ts CHANGED
@@ -5,7 +5,7 @@ import { PlaceholderOptions, definePlaceholder } from "@prosekit/extensions/plac
5
5
  import { defineReadonly } from "@prosekit/extensions/readonly";
6
6
 
7
7
  //#region src/extensions/extension.d.ts
8
- declare function defineEditorExtensionImpl(): import("@prosekit/core").Union<readonly [import("@prosekit/extensions/paragraph").ParagraphExtension, import("@prosekit/extensions/doc").DocExtension, import("@prosekit/extensions/text").TextExtension, import("@prosekit/extensions/blockquote").BlockquoteExtension, import("@prosekit/extensions/list").ListExtension, import("@prosekit/extensions/heading").HeadingExtension, import("@prosekit/core").Union<readonly [import("@prosekit/extensions/table").TableSpecExtension, import("@prosekit/extensions/table").TableRowSpecExtension, import("@prosekit/extensions/table").TableCellSpecExtension, import("@prosekit/extensions/table").TableHeaderCellSpecExtension, import("@prosekit/core").PlainExtension, import("@prosekit/extensions/table").TableCommandsExtension, import("@prosekit/core").PlainExtension]>, import("@prosekit/extensions/code-block").CodeBlockExtension, import("@prosekit/extensions/horizontal-rule").HorizontalRuleExtension, import("@prosekit/core").Union<readonly [import("@prosekit/core").Extension<{
8
+ declare function defineEditorExtensionImpl(): import("@prosekit/core").Union<readonly [import("@prosekit/extensions/paragraph").ParagraphExtension, import("@prosekit/extensions/doc").DocExtension, import("@prosekit/extensions/text").TextExtension, import("@prosekit/extensions/blockquote").BlockquoteExtension, import("@prosekit/extensions/list").ListExtension, import("@prosekit/core").Union<readonly [import("@prosekit/extensions/heading").HeadingSpecExtension, import("@prosekit/core").PlainExtension, import("@prosekit/extensions/heading").HeadingCommandsExtension, import("@prosekit/core").PlainExtension]>, import("@prosekit/core").Union<readonly [import("@prosekit/extensions/table").TableSpecExtension, import("@prosekit/extensions/table").TableRowSpecExtension, import("@prosekit/extensions/table").TableCellSpecExtension, import("@prosekit/extensions/table").TableHeaderCellSpecExtension, import("@prosekit/core").PlainExtension, import("@prosekit/extensions/table").TableCommandsExtension, import("@prosekit/core").PlainExtension]>, import("@prosekit/extensions/code-block").CodeBlockExtension, import("@prosekit/extensions/horizontal-rule").HorizontalRuleExtension, import("@prosekit/core").Union<readonly [import("@prosekit/core").Extension<{
9
9
  Marks: {
10
10
  mdMark: import("@prosekit/pm/model").Attrs;
11
11
  };
@@ -50,7 +50,7 @@ declare function defineEditorExtensionImpl(): import("@prosekit/core").Union<rea
50
50
  toggleCode: [];
51
51
  toggleDel: [];
52
52
  };
53
- }>, import("@prosekit/core").PlainExtension]>, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").BaseCommandsExtension, import("@prosekit/core").HistoryExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension]>;
53
+ }>, import("@prosekit/core").PlainExtension]>, import("@prosekit/core").PlainExtension, import("@prosekit/core").BaseCommandsExtension, import("@prosekit/core").HistoryExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension]>;
54
54
  type EditorExtension = ReturnType<typeof defineEditorExtensionImpl>;
55
55
  declare function defineEditorExtension(): EditorExtension;
56
56
  type TypedEditor = Editor<EditorExtension>;
@@ -76,13 +76,16 @@ type WikilinkClickHandler = (payload: WikilinkClickPayload) => void;
76
76
  declare function defineWikilinkClickHandler(onClick: WikilinkClickHandler): PlainExtension;
77
77
  //#endregion
78
78
  //#region src/extensions/images.d.ts
79
+ type ImageUrlResolver = (src: string) => string | undefined;
80
+ type ImagePasteHandler = (file: File) => string | undefined | Promise<string | undefined>;
81
+ type ImageSaveErrorHandler = (error: unknown, file: File) => void;
79
82
  interface ImageOptions {
80
83
  /** Map a markdown `src` to a displayable URL, or `undefined` to skip rendering. */
81
- resolveImageUrl: (src: string) => string | undefined;
84
+ resolveImageUrl: ImageUrlResolver;
82
85
  /** Persist a pasted/dropped image file and return its markdown `src`, or `undefined` to decline. */
83
- onImagePaste?: (file: File) => Promise<string | undefined>;
86
+ onImagePaste?: ImagePasteHandler;
84
87
  /** Called when persisting a pasted/dropped image throws. Defaults to `console.error`. */
85
- onImageSaveError?: (error: Error, file: File) => void;
88
+ onImageSaveError?: ImageSaveErrorHandler;
86
89
  }
87
90
  /** Inline image rendering (widget decorations) plus paste/drop persistence. */
88
91
  declare function defineImages(options: ImageOptions): PlainExtension;
@@ -95,17 +98,11 @@ declare const EDITOR_KEY_BINDINGS: {
95
98
  readonly 'Mod-e': "Inline code";
96
99
  readonly 'Mod-Shift-x': "Strikethrough";
97
100
  readonly 'Mod-1': "Heading 1";
98
- readonly 'Mod-Alt-1': "Heading 1";
99
101
  readonly 'Mod-2': "Heading 2";
100
- readonly 'Mod-Alt-2': "Heading 2";
101
102
  readonly 'Mod-3': "Heading 3";
102
- readonly 'Mod-Alt-3': "Heading 3";
103
103
  readonly 'Mod-4': "Heading 4";
104
- readonly 'Mod-Alt-4': "Heading 4";
105
104
  readonly 'Mod-5': "Heading 5";
106
- readonly 'Mod-Alt-5': "Heading 5";
107
105
  readonly 'Mod-6': "Heading 6";
108
- readonly 'Mod-Alt-6': "Heading 6";
109
106
  };
110
107
  //#endregion
111
108
  //#region src/extensions/code-block-languages.d.ts
package/dist/index.js CHANGED
@@ -1,15 +1,15 @@
1
- import{createEditor as e,defineBaseCommands as t,defineBaseKeymap as n,defineCommands as r,defineHistory as i,defineKeymap as a,defineMarkSpec as o,definePlugin as s,getMarkType as c,isApple as l,toggleNode as u,union as d,withSkipCodeBlock as ee}from"@prosekit/core";import{defineBlockquote as te}from"@prosekit/extensions/blockquote";import{defineCodeBlock as ne,defineCodeBlockHighlight as re}from"@prosekit/extensions/code-block";import{defineDoc as ie}from"@prosekit/extensions/doc";import{defineGapCursor as ae}from"@prosekit/extensions/gap-cursor";import{defineHeading as oe}from"@prosekit/extensions/heading";import{defineHorizontalRule as se}from"@prosekit/extensions/horizontal-rule";import{defineList as ce}from"@prosekit/extensions/list";import{defineModClickPrevention as le}from"@prosekit/extensions/mod-click-prevention";import{defineParagraph as ue}from"@prosekit/extensions/paragraph";import{defineText as de}from"@prosekit/extensions/text";import{defineVirtualSelection as fe}from"@prosekit/extensions/virtual-selection";import{LanguageDescription as pe}from"@codemirror/language";import{languages as me}from"@codemirror/language-data";import{classHighlighter as he}from"@lezer/highlight";import{createParser as ge}from"prosemirror-highlight/lezer";import{Plugin as f,PluginKey as p,TextSelection as m}from"@prosekit/pm/state";import{ReplaceStep as _e,Step as h,StepResult as ve,Transform as g}from"@prosekit/pm/transform";import{Mark as ye}from"@prosekit/pm/model";import{GFM as be,parser as xe}from"@lezer/markdown";import{defineTableCellSpec as Se,defineTableCommands as Ce,defineTableDropIndicator as we,defineTableHeaderCellSpec as Te,defineTableRowSpec as Ee,defineTableSpec as De}from"@prosekit/extensions/table";import{tableEditing as Oe}from"prosemirror-tables";import{Decoration as _,DecorationSet as v}from"@prosekit/pm/view";import{definePlaceholder as ke}from"@prosekit/extensions/placeholder";import{defineReadonly as Ae}from"@prosekit/extensions/readonly";const y=new Map;async function je(e){let t=pe.matchLanguageName(me,e,!0);if(!t){y.set(e,null);return}let n=t.support;if(!n)try{n=await t.load()}catch(t){console.error(`[meowdown] Failed to load language "${e}":`,t),y.set(e,null)}if(y.has(e))return;if(!n){y.set(e,null);return}let r=ge({parse:e=>n.language.parser.parse(e.content),highlighter:he});y.set(e,r)}const Me=e=>{let t=e.language?.trim();if(!t)return[];let n=y.get(t);return n?n(e):n===null?[]:je(t)};function Ne(){return re({parser:Me,nodeTypes:[`codeBlock`]})}const Pe=[1,2,3,4,5,6];function Fe(){return a(Object.fromEntries(Pe.map(e=>[`Mod-${e}`,ee(u({type:`heading`,attrs:{level:e}}))])))}function Ie(e){let[t,n,r]=e;return[t,n,r.map(e=>e.toJSON())]}function Le(e,t){let[n,r,i]=t;return[n,r,i.map(t=>ye.fromJSON(e,t))]}var b=class e extends h{constructor(e){super(),this.chunks=e}apply(e){if(this.chunks.length===0)return ve.ok(e);let t=e.content.size,n;for(let[r,i,a]of this.chunks){if(r>=i)continue;let o=Math.max(0,Math.min(r,t)),s=Math.max(o,Math.min(i,t));o>=s||e.nodesBetween(o,s,(t,r)=>{if(!t.isText)return!0;let i=Math.max(o,r),c=Math.min(s,r+t.nodeSize);if(i>=c)return!1;let l=t.marks;for(let t of l)t.isInSet(a)||(n??=new g(e),n.removeMark(i,c,t));for(let t of a)t.isInSet(l)||(n??=new g(e),n.addMark(i,c,t));return!1})}return ve.ok(n?n.doc:e)}invert(e){if(this.chunks.length===0)return Re;let t=this.chunks[0][0],n=this.chunks[0][1];for(let[,e]of this.chunks)e>n&&(n=e);let r=e.content.size,i=Math.max(0,Math.min(t,r)),a=Math.max(i,Math.min(n,r));return new _e(i,a,e.slice(i,a),!1)}map(e){return null}toJSON(){return{stepType:`batchSetMark`,chunks:this.chunks.map(Ie)}}static fromJSON(t,n){let r=n.chunks;return new e(r.map(e=>Le(t,e)))}};h.jsonID(`batchSetMark`,b);const Re=new b([]);function ze(e){return e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122||e===45||e===95||e>127&&/[\p{L}\p{N}]/u.test(String.fromCharCode(e))}function Be(e){return e>=65&&e<=90||e>=97&&e<=122||e>127&&/\p{L}/u.test(String.fromCharCode(e))}const Ve={defineNodes:[{name:`Hashtag`}],parseInline:[{name:`Hashtag`,parse(e,t,n){if(t!==35||!/\s|^$/.test(e.slice(n-1,n)))return-1;let r=n+1,i=!1;for(;r<e.end;){let t=e.char(r);if(!ze(t))break;i||=Be(t),r++}return i?e.addElement(e.elt(`Hashtag`,n,r)):-1}}]},He={defineNodes:[{name:`Wikilink`},{name:`WikilinkMark`}],parseInline:[{name:`Wikilink`,before:`Link`,parse(e,t,n){if(t!==91||e.char(n+1)!==91)return-1;let r=!1;for(let t=n+2;t<e.end-1;t++){let i=e.char(t);if(i===93){if(e.char(t+1)!==93||!r)return-1;let i=t+2;return e.addElement(e.elt(`Wikilink`,n,i,[e.elt(`WikilinkMark`,n,n+2),e.elt(`WikilinkMark`,t,i)]))}if(i===91||i===10)return-1;i!==32&&i!==9&&(r=!0)}return-1}}]};function Ue(e){return e.end}const x=xe.configure([be,Ve,He]),We=x.configure({parseInline:[{name:`SkipInline`,before:`Escape`,parse:Ue}]});function S(e){return x.parseInline(e,0)}function C(e,t,n=[]){for(let r of e)t(r)&&n.push(r),C(r.children,t,n);return n}function Ge(e){let t={};for(let n of e.nodeSet.types)t[n.name]=n.id;return t}const w=Ge(x);function Ke(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!e[n].eq(t[n]))return!1;return!0}const T=new Map([[w.Emphasis,`mdEm`],[w.StrongEmphasis,`mdStrong`],[w.InlineCode,`mdCode`],[w.Strikethrough,`mdDel`],[w.EmphasisMark,`mdMark`],[w.CodeMark,`mdMark`],[w.LinkMark,`mdMark`],[w.StrikethroughMark,`mdMark`],[w.URL,`mdLinkUri`],[w.Hashtag,`mdTag`],[w.Wikilink,`mdWikilink`],[w.WikilinkMark,`mdMark`]]);function qe(e,t){let n=S(t),r=[];return E(n,[],0,t.length,t,e,r),r}function E(e,t,n,r,i,a,o){let s=n;for(let n of e){if(n.from>s&&D(o,s,n.from,t),n.type===w.Link||n.type===w.Image)Je(n,t,i,a,o);else{let e=T.get(n.type),r=e?[...t,a.marks[e].create()]:t;n.children.length===0?D(o,n.from,n.to,r):E(n.children,r,n.from,n.to,i,a,o)}s=n.to}s<r&&D(o,s,r,t)}function Je(e,t,n,r,i){let a=-1,o=null,s=0;for(let t of e.children)t.type===w.LinkMark?(s++,s===2&&(a=t.from)):t.type===w.URL&&o===null&&(o=t);let c=o?n.slice(o.from,o.to):``,l=c&&r.marks.mdLinkText?r.marks.mdLinkText.create({href:c}):null,u=e=>a>=0&&e<a&&l!==null,d=e.from;for(let a of e.children){if(a.from>d){let e=u(d)?[...t,l]:t;D(i,d,a.from,e)}let e=u(a.from)?[...t,l]:t,o=T.get(a.type),s=o?[...e,r.marks[o].create()]:e;a.children.length===0?D(i,a.from,a.to,s):E(a.children,s,a.from,a.to,n,r,i),d=a.to}d<e.to&&D(i,d,e.to,t)}function D(e,t,n,r){if(t>=n)return;let i=e.at(-1);if(i&&i[1]===t&&Ke(i[2],r)){e[e.length-1]=[i[0],n,i[2]];return}e.push([t,n,r])}const O=`inline-marks-applied`,Ye=new WeakMap;let Xe=0,Ze=0;function Qe(e,t,n){let r=Ye.get(e);if(r?Ze++:(Xe++,r=qe(n,e.textContent),Ye.set(e,r)),t===0)return r;let i=[];for(let[e,n,a]of r)i.push([e+t,n+t,a]);return i}function $e(e,t){let n=1/0,r=-1/0;for(let t of e)for(let e of t.mapping.maps)e.forEach((e,t,i,a)=>{i<n&&(n=i),a>r&&(r=a)});let i=t.doc.content.size;return n>r?{from:0,to:i}:{from:Math.max(0,n),to:Math.min(i,r)}}function et(e,t){let n=[];return e.doc.nodesBetween(t.from,t.to,(t,r)=>{if(t.type.spec.code)return!1;if(!t.isTextblock)return!0;if(t.childCount===0)return!1;let i=Qe(t,r+1,e.schema);return i.length>0&&n.push(...i),!1}),n}function tt(){return new f({key:new p(`inline-mark`),appendTransaction(e,t,n){for(let t of e)if(t.getMeta(O))return null;let r=et(n,$e(e,n));if(r.length===0)return null;let i=n.tr.step(new b(r));return i.setMeta(O,!0),i.setMeta(`addToHistory`,!1),i},view(e){return e.dispatch(nt(e.state)),{}}})}function nt(e){return e.tr.setMeta(`inline-marks-trigger`,!0)}function rt(){return s(tt())}function it(){return o({name:`mdMark`,inclusive:!1,toDOM:()=>[`span`,{class:`md-mark`},0],parseDOM:[{tag:`span.md-mark`}]})}function at(){return o({name:`mdEm`,toDOM:()=>[`em`,0],parseDOM:[{tag:`em`}]})}function ot(){return o({name:`mdStrong`,toDOM:()=>[`strong`,0],parseDOM:[{tag:`strong`}]})}function st(){return o({name:`mdCode`,toDOM:()=>[`code`,0],parseDOM:[{tag:`code`}]})}function ct(){return o({name:`mdLinkText`,inclusive:!1,attrs:{href:{default:``}},toDOM:e=>[`a`,{href:e.attrs.href},0],parseDOM:[{tag:`a`,getAttrs:e=>({href:e.getAttribute(`href`)??``})}]})}function lt(){return o({name:`mdLinkUri`,inclusive:!1,toDOM:()=>[`span`,{class:`md-link-uri`},0],parseDOM:[{tag:`span.md-link-uri`}]})}function ut(){return o({name:`mdDel`,toDOM:()=>[`del`,0],parseDOM:[{tag:`del`}]})}function dt(){return o({name:`mdTag`,toDOM:()=>[`span`,{class:`md-tag`},0],parseDOM:[{tag:`span.md-tag`}]})}function ft(){return o({name:`mdWikilink`,inclusive:!1,toDOM:()=>[`span`,{class:`md-wikilink`},0],parseDOM:[{tag:`span.md-wikilink`}]})}function pt(){return d(it(),at(),ot(),st(),ct(),lt(),ut(),dt(),ft())}function k(e,t=0){let n=t,r=0;for(let t=0;t<e.length;t++)e.charCodeAt(t)===96?(r++,r>n&&(n=r)):r=0;return n}const A={em:{node:w.Emphasis,delim:`*`},strong:{node:w.StrongEmphasis,delim:`**`},code:{node:w.InlineCode,delim:"`"},del:{node:w.Strikethrough,delim:`~~`}},mt=new Set([w.EmphasisMark,w.CodeMark,w.LinkMark,w.StrikethroughMark]);function j(e){return[e.children[0],e.children.at(-1)]}function M(e){let{type:t,children:n}=e;if(t===w.Emphasis||t===w.StrongEmphasis||t===w.Strikethrough)return[n[0].to,n.at(-1).from];if(t===w.Link||t===w.Image){let e=n.find((e,t)=>t>0&&e.type===w.LinkMark);return e?[n[0].to,e.from]:null}return null}function N(e,t,n){for(let r of e){if(r.to<=t||r.from>=n||t<=r.from&&r.to<=n)continue;let i=M(r);return i&&i[0]<=t&&n<=i[1]?N(r.children,t,n):N(e,Math.min(t,r.from),Math.max(n,r.to))}return[t,n]}function P(e,t,n){for(let r of e)if(!(r.to<=t||r.from>=n)&&(t>r.from||r.to>n))return P(e,Math.min(t,r.from),Math.max(n,r.to));return[t,n]}const F=e=>e===` `||e===` `;function ht(e,t,n){for(;t<n&&F(e[t]);)t++;for(;n>t&&F(e[n-1]);)n--;return[t,n]}function gt(e,t,n,r){let i=C(S(e),e=>e.type===r.node||mt.has(e.type));for(let r=t;r<n;r++)if(!F(e[r])&&i.every(e=>!(e.from<=r&&r<e.to)))return!1;return!0}function _t(e,t,n,r,i){let a=S(e),o=C(a,e=>e.type===r.node);return i?bt(e,o,t,n):vt(e,a,o,t,n,r)}function vt(e,t,n,r,i,a){for(let e=0;e!==i-r;){e=i-r,[r,i]=N(t,r,i);for(let e of n)e.to===r&&(r=e.from),e.from===i&&(i=e.to)}let o=[];for(let e of n)if(r<=e.from&&e.to<=i){let[t,n]=j(e);o.push({from:t.from,to:t.to,insert:``}),o.push({from:n.from,to:n.to,insert:``})}let[s,c]=yt(e,r,i,o,a);return o.push({from:r,to:r,insert:s},{from:i,to:i,insert:c}),o}function yt(e,t,n,r,i){if(i.node!==w.InlineCode)return[i.delim,i.delim];let a=e.slice(t,n);for(let e of[...r].sort((e,t)=>t.from-e.from))a=a.slice(0,e.from-t)+a.slice(e.to-t);let o="`".repeat(k(a)+1),s=a.startsWith("`")||a.endsWith("`")?` `:``;return[o+s,s+o]}function bt(e,t,n,r){let i=[];for(let a of t){if(a.to<=n||a.from>=r)continue;let[t,o]=j(a),s=Math.max(n,t.to),c=Math.min(r,o.from);for(s>=c&&([s,c]=[t.to,o.from]),[s,c]=P(a.children.slice(1,-1),s,c);s>t.to&&F(e[s-1]);)s--;for(;c<o.from&&F(e[c]);)c++;s>t.to?i.push({from:s,to:s,insert:e.slice(o.from,o.to)}):i.push({from:t.from,to:t.to,insert:``}),c<o.from?i.push({from:c,to:c,insert:e.slice(t.from,t.to)}):i.push({from:o.from,to:o.to,insert:``})}return i}function xt(e,t,n){let{delim:r}=n,i=r.length;if(e.slice(t-i,t)===r&&e.startsWith(r,t)&&e[t-i-1]!==r[0]&&e[t+i]!==r[0])return{kind:`unwrap`,from:t-i,to:t+i};let a=S(e),o=C(a,e=>e.type===n.node).findLast(e=>e.from<=t&&t<=e.to);if(o){let[e,n]=j(o);return{kind:`move`,pos:t===o.from?e.to:t===o.to?n.from:o.to}}return I(a,t)||e[t-1]===r[0]||e[t]===r[0]?null:{kind:`insert`,pos:t}}function I(e,t){for(let n of e)if(n.from<t&&t<n.to){let e=M(n);return!e||t<e[0]||t>e[1]?!0:I(n.children,t)}return!1}function L(e){return(t,n)=>{if(t.selection.empty)return St(e,t,n);let{from:r,to:i,anchor:a,head:o}=t.selection,s=[];t.doc.nodesBetween(r,i,(t,n)=>{if(t.type.spec.code)return!1;if(!t.isTextblock)return!0;let a=t.textContent,o=n+1,[c,l]=ht(a,Math.max(r-o,0),Math.min(i-o,a.length));return c<l&&s.push({text:a,base:o,from:c,to:l,active:gt(a,c,l,e)}),!1});let c=s.length>0&&s.every(e=>e.active),l=s.filter(e=>c||!e.active).flatMap(t=>_t(t.text,t.from,t.to,e,c).map(e=>({from:e.from+t.base,to:e.to+t.base,insert:e.insert})));if(l.length===0)return!1;if(n){let e=t.tr;l.sort((e,t)=>t.from-e.from||t.to-e.to);for(let t of l)t.insert?e.insertText(t.insert,t.from,t.to):e.delete(t.from,t.to);e.setSelection(m.create(e.doc,e.mapping.map(a,a<=o?1:-1),e.mapping.map(o,o<a?1:-1))),n(e.scrollIntoView())}return!0}}function St(e,t,n){let{$from:r}=t.selection,i=r.parent;if(!i.isTextblock||i.type.spec.code)return!1;let a=xt(i.textContent,r.parentOffset,e);if(!a)return!1;if(n){let i=r.start(),o=t.tr;a.kind===`unwrap`&&o.delete(i+a.from,i+a.to),a.kind===`move`&&o.setSelection(m.create(o.doc,i+a.pos)),a.kind===`insert`&&(o.insertText(e.delim+e.delim,i+a.pos),o.setSelection(m.create(o.doc,i+a.pos+e.delim.length))),n(o.scrollIntoView())}return!0}function Ct(){return d(r({toggleEm:()=>L(A.em),toggleStrong:()=>L(A.strong),toggleCode:()=>L(A.code),toggleDel:()=>L(A.del)}),a({"Mod-b":L(A.strong),"Mod-i":L(A.em),"Mod-e":L(A.code),"Mod-Shift-x":L(A.del)}))}function wt(){return d(De(),Ee(),Se(),Te(),s(Oe()),Ce(),we())}function Tt(){return d(ue(),ie(),de(),te(),ce(),oe(),wt(),ne(),se(),pt(),Ne(),rt(),Ct(),Fe(),n(),t(),i(),ae(),fe(),le())}function R(){return Tt()}const Et=new Set([`mdStrong`,`mdEm`,`mdCode`,`mdDel`,`mdLinkText`,`mdLinkUri`,`mdWikilink`]),Dt=new Set([`mdMark`,`mdLinkUri`]),Ot=new Set([`mdMark`,`mdLinkUri`]),z=new Set([`mdLinkText`,`mdLinkUri`]),kt=new Set([`mdStrong`,`mdEm`,`mdCode`,`mdDel`,`mdWikilink`]);function At(e){return new f({key:new p(`mark-mode`),props:{attributes:{"data-mark-mode":e},decorations:e===`focus`?e=>Nt(e):void 0,clipboardTextSerializer:e===`show`?void 0:Mt}})}function jt(e){return s(At(e))}function Mt(e){let t=[];return e.content.forEach(e=>{let n=[];e.descendants(e=>!e.isText||!e.text?!0:(e.marks.some(e=>Ot.has(e.type.name))||n.push(e.text),!1)),t.push(n.join(``))}),t.join(`
2
- `)}function Nt(e){let{$anchor:t,empty:n}=e.selection;if(!n)return v.empty;let r=t.parent;if(!r.isTextblock)return null;let i=t.start(),a=t.parentOffset,o=Pt(r,a);if(o.size===0)return v.empty;let s=[],c=new Set,l=!1;for(let e of o)if(z.has(e)){if(l)continue;l=!0,It(r,i,a,s,c)}else Ft(r,i,e,a,s,c);let u=s.map(([e,t])=>_.inline(e,t,{class:`show`}));return v.create(e.doc,u)}function Pt(e,t){let n=new Set,r=0;return e.forEach(e=>{let i=r+e.nodeSize;if(t>=r&&t<=i)for(let t of e.marks){let e=t.type.name;Et.has(e)&&n.add(e)}r=i}),n}function Ft(e,t,n,r,i,a){let o=t,s=0,c=-1,l=-1;e.forEach(u=>{let d=u.marks.some(e=>e.type.name===n);d&&c===-1&&(c=o,l=s),!d&&c!==-1&&(r>=l&&r<=s&&V(e,t,c,o,i,a),c=-1,l=-1),o+=u.nodeSize,s+=u.nodeSize}),c!==-1&&r>=l&&r<=s&&V(e,t,c,o,i,a)}function It(e,t,n,r,i){let a=e.childCount;if(a===0)return;let o=-1,s=0;for(let t=0;t<a;t++){let r=e.child(t),i=s+r.nodeSize;if(n>=s&&n<=i&&r.marks.some(e=>z.has(e.type.name))){o=t;break}s=i}if(o===-1)return;let c=o;for(;c>0&&B(e.child(c-1));)c--;let l=o;for(;l<a-1&&B(e.child(l+1));)l++;let u=t;for(let t=0;t<c;t++)u+=e.child(t).nodeSize;let d=u;for(let t=c;t<=l;t++)d+=e.child(t).nodeSize;V(e,t,u,d,r,i)}function B(e){let t=!1,n=!1,r=!1;for(let i of e.marks){let e=i.type.name;e===`mdMark`?t=!0:z.has(e)?n=!0:kt.has(e)&&(r=!0)}return!!(n||t&&!r)}function V(e,t,n,r,i,a){let o=t;e.forEach(e=>{let t=o,s=o+e.nodeSize;if(t>=n&&s<=r)for(let n of e.marks){let e=n.type.name;if(Dt.has(e)){let e=`${t}_${s}`;a.has(e)||(a.add(e),i.push([t,s]));break}}o=s})}const Lt=new p(`meowdown-wikilink-click`);function Rt(e,t){let n=c(e.schema,`mdWikilink`),r=e.doc.resolve(t),i=r.parent;if(!i.isTextblock||i.type.spec.code)return;let a=r.start(),o=-1,s=-1,l,u=0;if(i.forEach(e=>{let r=a+u;u+=e.nodeSize;let i=a+u;n.isInSet(e.marks)?(o<0&&(o=r),s=i):(o>=0&&o<=t&&t<=s&&(l={from:o,to:s}),o=-1)}),o>=0&&o<=t&&t<=s&&(l={from:o,to:s}),l)return{from:l.from,to:l.to,target:zt(e.doc.textBetween(l.from,l.to))}}function zt(e){let t=e.replace(/^\[\[/u,``).replace(/\]\]$/u,``),n=t.indexOf(`|`);return(n>=0?t.slice(0,n):t).trim()}function Bt(e){let t;return s(new f({key:Lt,props:{handleDOMEvents:{mousedown:e=>{let{from:n,to:r,empty:i}=e.state.selection;return t={from:n,to:r,empty:i},!1}},handleClick:(n,r,i)=>{if(!i.target?.closest?.(`.md-wikilink`))return!1;let a=Rt(n.state,r);return!a||!(l?i.metaKey:i.ctrlKey)&&t?.empty&&t.from>=a.from&&t.to<=a.to?!1:(e({target:a.target,event:i}),!0)}}}))}function Vt(e){let t=[],n=C(S(e),e=>e.type===w.Image);for(let r of n){let n=r.children.find(e=>e.type===w.URL),i=r.children.filter(e=>e.type===w.LinkMark);!n||i.length<2||t.push({from:r.from,to:r.to,alt:e.slice(i[0].to,i[1].from),src:e.slice(n.from,n.to)})}return t}const H=new p(`meowdown-images`);function Ht(e){let t=[];return e.doc.descendants((e,n)=>{if(e.type.spec.code)return!1;if(!e.isTextblock)return!0;if(e.childCount===0)return!1;let r=!0;if(e.forEach(e=>{e.isText||(r=!1)}),!r)return!1;for(let r of Vt(e.textContent))t.push({widgetAt:n+e.nodeSize-1,alt:r.alt,src:r.src});return!1}),t}function U(e,t){let n=[];for(let r of Ht(e)){let e=t.resolveImageUrl(r.src);e&&n.push(_.widget(r.widgetAt,()=>{let t=document.createElement(`div`);t.className=`md-image`,t.contentEditable=`false`;let n=document.createElement(`img`);return n.src=e,n.alt=r.alt,n.draggable=!1,t.appendChild(n),t},{key:`md-image:${e}`,side:1}))}return v.create(e.doc,n)}function Ut(e){return new f({key:H,state:{init:(t,n)=>U(n,e),apply:(t,n,r,i)=>t.docChanged?U(i,e):n},props:{decorations:e=>H.getState(e)}})}function W(e){return e?Array.from(e.files).filter(e=>e.type.startsWith(`image/`)):[]}function Wt(e,t,n){e.onImageSaveError?e.onImageSaveError(t,n):console.error(`[meowdown] failed to save pasted image:`,t)}async function G(e,t,n,r){let i=r;for(let r of t){let t;try{t=await n.onImagePaste(r)}catch(e){Wt(n,e,r);continue}if(!t||e.isDestroyed)continue;let a=`![](${t})`,o=i==null?e.state.tr.insertText(a):e.state.tr.insertText(a,i);e.dispatch(o),i!=null&&(i+=a.length)}}function Gt(e){return new f({props:{handlePaste:(t,n)=>{let r=W(n.clipboardData),i=e.onImagePaste;return r.length===0||!i?!1:(G(t,r,{...e,onImagePaste:i}),!0)},handleDrop:(t,n)=>{let r=W(n.dataTransfer),i=e.onImagePaste;if(r.length===0||!i)return!1;let a=t.posAtCoords({left:n.clientX,top:n.clientY});return G(t,r,{...e,onImagePaste:i},a?.pos),!0}}})}function Kt(e){return d(s(Ut(e)),s(Gt(e)))}const qt={"Mod-b":`Bold`,"Mod-i":`Italic`,"Mod-e":`Inline code`,"Mod-Shift-x":`Strikethrough`,"Mod-1":`Heading 1`,"Mod-Alt-1":`Heading 1`,"Mod-2":`Heading 2`,"Mod-Alt-2":`Heading 2`,"Mod-3":`Heading 3`,"Mod-Alt-3":`Heading 3`,"Mod-4":`Heading 4`,"Mod-Alt-4":`Heading 4`,"Mod-5":`Heading 5`,"Mod-Alt-5":`Heading 5`,"Mod-6":`Heading 6`,"Mod-Alt-6":`Heading 6`},Jt=new Set([`MscGen`,`Xù`,`MsGenny`,`Angular Template`]),Yt=me.map(e=>e.name).filter(e=>!Jt.has(e)).map(e=>({label:e,value:e.toLowerCase()})).concat({label:`Plain text`,value:``}).sort((e,t)=>e.label.localeCompare(t.label));function K(e){let t=new Zt;return q(e,t),t.finish()}const Xt=[``,`# `,`## `,`### `,`#### `,`##### `,`###### `];var Zt=class{constructor(){this.parts=[],this.linePrefix=``,this.pendingFirst=null,this.atLineStart=!0,this.deferredBlankPrefix=null}write(e){if(e===``)return;if(this.emitDeferredBlankLine(),this.atLineStart&&=(this.parts.push(this.pendingFirst??this.linePrefix),this.pendingFirst=null,!1),!e.includes(`
1
+ import{Priority as e,createEditor as t,defineBaseCommands as n,defineBaseKeymap as r,defineCommands as i,defineHistory as a,defineKeymap as o,defineMarkSpec as s,definePlugin as c,getMarkType as l,isApple as u,isAtBlockStart as d,toggleNode as ee,union as f,unsetBlockType as te,withPriority as ne,withSkipCodeBlock as re}from"@prosekit/core";import{defineBlockquote as ie}from"@prosekit/extensions/blockquote";import{defineCodeBlock as ae,defineCodeBlockHighlight as oe}from"@prosekit/extensions/code-block";import{defineDoc as se}from"@prosekit/extensions/doc";import{defineGapCursor as ce}from"@prosekit/extensions/gap-cursor";import{defineHorizontalRule as le}from"@prosekit/extensions/horizontal-rule";import{defineList as ue}from"@prosekit/extensions/list";import{defineModClickPrevention as de}from"@prosekit/extensions/mod-click-prevention";import{defineParagraph as fe}from"@prosekit/extensions/paragraph";import{defineText as pe}from"@prosekit/extensions/text";import{defineVirtualSelection as me}from"@prosekit/extensions/virtual-selection";import{LanguageDescription as he}from"@codemirror/language";import{languages as p}from"@codemirror/language-data";import{classHighlighter as ge}from"@lezer/highlight";import{createParser as _e}from"prosemirror-highlight/lezer";import{defineHeadingCommands as ve,defineHeadingInputRule as ye,defineHeadingSpec as be}from"@prosekit/extensions/heading";import{Plugin as m,PluginKey as h,TextSelection as g}from"@prosekit/pm/state";import{ReplaceStep as xe,Step as _,StepResult as v,Transform as Se}from"@prosekit/pm/transform";import{Mark as Ce}from"@prosekit/pm/model";import{GFM as we,parser as Te}from"@lezer/markdown";import{defineTableCellSpec as Ee,defineTableCommands as De,defineTableDropIndicator as Oe,defineTableHeaderCellSpec as ke,defineTableRowSpec as Ae,defineTableSpec as je}from"@prosekit/extensions/table";import{tableEditing as Me}from"prosemirror-tables";import{Decoration as Ne,DecorationSet as y}from"@prosekit/pm/view";import{definePlaceholder as Pe}from"@prosekit/extensions/placeholder";import{defineReadonly as Fe}from"@prosekit/extensions/readonly";const b=new Map;async function Ie(e){let t=he.matchLanguageName(p,e,!0);if(!t){b.set(e,null);return}let n=t.support;if(!n)try{n=await t.load()}catch(t){console.error(`[meowdown] Failed to load language "${e}":`,t),b.set(e,null)}if(b.has(e))return;if(!n){b.set(e,null);return}let r=_e({parse:e=>n.language.parser.parse(e.content),highlighter:ge});b.set(e,r)}const Le=e=>{let t=e.language?.trim();if(!t)return[];let n=b.get(t);return n?n(e):n===null?[]:Ie(t)};function Re(){return oe({parser:Le,nodeTypes:[`codeBlock`]})}function x(e){return re(ee({type:`heading`,attrs:{level:e}}))}const ze=(e,t,n)=>d(e,n)?.parent.type.name===`heading`?te()(e,t,n):!1;function Be(){return o({"Mod-1":x(1),"Mod-2":x(2),"Mod-3":x(3),"Mod-4":x(4),"Mod-5":x(5),"Mod-6":x(6),Backspace:ze})}function Ve(){return f(be(),ye(),ve(),Be())}function He(e){let[t,n,r]=e;return[t,n,r.map(e=>e.toJSON())]}function Ue(e,t){let[n,r,i]=t;return[n,r,i.map(t=>Ce.fromJSON(e,t))]}var S=class e extends _{constructor(e){super(),this.chunks=e}apply(e){if(this.chunks.length===0)return v.ok(e);let t=e.content.size,n;for(let[r,i,a]of this.chunks){if(r>=i)continue;let o=Math.max(0,Math.min(r,t)),s=Math.max(o,Math.min(i,t));o>=s||e.nodesBetween(o,s,(t,r)=>{if(!t.isText)return!0;let i=Math.max(o,r),c=Math.min(s,r+t.nodeSize);if(i>=c)return!1;let l=t.marks;for(let t of l)t.isInSet(a)||(n??=new Se(e),n.removeMark(i,c,t));for(let t of a)t.isInSet(l)||(n??=new Se(e),n.addMark(i,c,t));return!1})}return v.ok(n?n.doc:e)}invert(e){if(this.chunks.length===0)return We;let t=this.chunks[0][0],n=this.chunks[0][1];for(let[,e]of this.chunks)e>n&&(n=e);let r=e.content.size,i=Math.max(0,Math.min(t,r)),a=Math.max(i,Math.min(n,r));return new xe(i,a,e.slice(i,a),!1)}map(e){return null}toJSON(){return{stepType:`batchSetMark`,chunks:this.chunks.map(He)}}static fromJSON(t,n){let r=n.chunks;return new e(r.map(e=>Ue(t,e)))}};_.jsonID(`batchSetMark`,S);const We=new S([]);function Ge(e){return e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122||e===45||e===95||e>127&&/[\p{L}\p{N}]/u.test(String.fromCharCode(e))}function Ke(e){return e>=65&&e<=90||e>=97&&e<=122||e>127&&/\p{L}/u.test(String.fromCharCode(e))}const qe={defineNodes:[{name:`Hashtag`}],parseInline:[{name:`Hashtag`,parse(e,t,n){if(t!==35||!/\s|^$/.test(e.slice(n-1,n)))return-1;let r=n+1,i=!1;for(;r<e.end;){let t=e.char(r);if(!Ge(t))break;i||=Ke(t),r++}return i?e.addElement(e.elt(`Hashtag`,n,r)):-1}}]},Je={defineNodes:[{name:`Wikilink`},{name:`WikilinkMark`}],parseInline:[{name:`Wikilink`,before:`Link`,parse(e,t,n){if(t!==91||e.char(n+1)!==91)return-1;let r=!1;for(let t=n+2;t<e.end-1;t++){let i=e.char(t);if(i===93){if(e.char(t+1)!==93||!r)return-1;let i=t+2;return e.addElement(e.elt(`Wikilink`,n,i,[e.elt(`WikilinkMark`,n,n+2),e.elt(`WikilinkMark`,t,i)]))}if(i===91||i===10)return-1;i!==32&&i!==9&&(r=!0)}return-1}}]};function Ye(e){return e.end}const C=Te.configure([we,qe,Je]),Xe=C.configure({parseInline:[{name:`SkipInline`,before:`Escape`,parse:Ye}]});function w(e){return C.parseInline(e,0)}function T(e,t,n=[]){for(let r of e)t(r)&&n.push(r),T(r.children,t,n);return n}function Ze(e){let t={};for(let n of e.nodeSet.types)t[n.name]=n.id;return t}const E=Ze(C);function Qe(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!e[n].eq(t[n]))return!1;return!0}const D=new Map([[E.Emphasis,`mdEm`],[E.StrongEmphasis,`mdStrong`],[E.InlineCode,`mdCode`],[E.Strikethrough,`mdDel`],[E.EmphasisMark,`mdMark`],[E.CodeMark,`mdMark`],[E.LinkMark,`mdMark`],[E.StrikethroughMark,`mdMark`],[E.URL,`mdLinkUri`],[E.Hashtag,`mdTag`],[E.Wikilink,`mdWikilink`],[E.WikilinkMark,`mdMark`]]);function $e(e,t){let n=w(t),r=[];return O(n,[],0,t.length,t,e,r),r}function O(e,t,n,r,i,a,o){let s=n;for(let n of e){if(n.from>s&&k(o,s,n.from,t),n.type===E.Link||n.type===E.Image)et(n,t,i,a,o);else{let e=D.get(n.type),r=e?[...t,a.marks[e].create()]:t;n.children.length===0?k(o,n.from,n.to,r):O(n.children,r,n.from,n.to,i,a,o)}s=n.to}s<r&&k(o,s,r,t)}function et(e,t,n,r,i){let a=-1,o=null,s=0;for(let t of e.children)t.type===E.LinkMark?(s++,s===2&&(a=t.from)):t.type===E.URL&&o===null&&(o=t);let c=o?n.slice(o.from,o.to):``,l=c&&r.marks.mdLinkText?r.marks.mdLinkText.create({href:c}):null,u=e=>a>=0&&e<a&&l!==null,d=e.from;for(let a of e.children){if(a.from>d){let e=u(d)?[...t,l]:t;k(i,d,a.from,e)}let e=u(a.from)?[...t,l]:t,o=D.get(a.type),s=o?[...e,r.marks[o].create()]:e;a.children.length===0?k(i,a.from,a.to,s):O(a.children,s,a.from,a.to,n,r,i),d=a.to}d<e.to&&k(i,d,e.to,t)}function k(e,t,n,r){if(t>=n)return;let i=e.at(-1);if(i&&i[1]===t&&Qe(i[2],r)){e[e.length-1]=[i[0],n,i[2]];return}e.push([t,n,r])}const A=`inline-marks-applied`,j=new WeakMap;let tt=0,nt=0;function rt(e,t,n){let r=j.get(e);if(r?nt++:(tt++,r=$e(n,e.textContent),j.set(e,r)),t===0)return r;let i=[];for(let[e,n,a]of r)i.push([e+t,n+t,a]);return i}function it(e,t){let n=1/0,r=-1/0;for(let t of e)for(let e of t.mapping.maps)e.forEach((e,t,i,a)=>{i<n&&(n=i),a>r&&(r=a)});let i=t.doc.content.size;return n>r?{from:0,to:i}:{from:Math.max(0,n),to:Math.min(i,r)}}function at(e,t){let n=[];return e.doc.nodesBetween(t.from,t.to,(t,r)=>{if(t.type.spec.code)return!1;if(!t.isTextblock)return!0;if(t.childCount===0)return!1;let i=rt(t,r+1,e.schema);return i.length>0&&n.push(...i),!1}),n}function ot(){return new m({key:new h(`inline-mark`),appendTransaction(e,t,n){for(let t of e)if(t.getMeta(A))return null;let r=at(n,it(e,n));if(r.length===0)return null;let i=n.tr.step(new S(r));return i.setMeta(A,!0),i.setMeta(`addToHistory`,!1),i},view(e){return e.dispatch(st(e.state)),{}}})}function st(e){return e.tr.setMeta(`inline-marks-trigger`,!0)}function ct(){return c(ot())}function lt(){return s({name:`mdMark`,inclusive:!1,toDOM:()=>[`span`,{class:`md-mark`},0],parseDOM:[{tag:`span.md-mark`}]})}function ut(){return s({name:`mdEm`,toDOM:()=>[`em`,0],parseDOM:[{tag:`em`}]})}function dt(){return s({name:`mdStrong`,toDOM:()=>[`strong`,0],parseDOM:[{tag:`strong`}]})}function ft(){return s({name:`mdCode`,toDOM:()=>[`code`,0],parseDOM:[{tag:`code`}]})}function pt(){return s({name:`mdLinkText`,inclusive:!1,attrs:{href:{default:``}},toDOM:e=>[`a`,{href:e.attrs.href},0],parseDOM:[{tag:`a`,getAttrs:e=>({href:e.getAttribute(`href`)??``})}]})}function mt(){return s({name:`mdLinkUri`,inclusive:!1,toDOM:()=>[`span`,{class:`md-link-uri`},0],parseDOM:[{tag:`span.md-link-uri`}]})}function ht(){return s({name:`mdDel`,toDOM:()=>[`del`,0],parseDOM:[{tag:`del`}]})}function gt(){return s({name:`mdTag`,toDOM:()=>[`span`,{class:`md-tag`},0],parseDOM:[{tag:`span.md-tag`}]})}function _t(){return s({name:`mdWikilink`,inclusive:!1,toDOM:()=>[`span`,{class:`md-wikilink`},0],parseDOM:[{tag:`span.md-wikilink`}]})}function vt(){return f(lt(),ut(),dt(),ft(),pt(),mt(),ht(),gt(),_t())}function M(e,t=0){let n=t,r=0;for(let t=0;t<e.length;t++)e.charCodeAt(t)===96?(r++,r>n&&(n=r)):r=0;return n}const N={em:{node:E.Emphasis,delim:`*`},strong:{node:E.StrongEmphasis,delim:`**`},code:{node:E.InlineCode,delim:"`"},del:{node:E.Strikethrough,delim:`~~`}},yt=new Set([E.EmphasisMark,E.CodeMark,E.LinkMark,E.StrikethroughMark]);function P(e){return[e.children[0],e.children.at(-1)]}function bt(e){let{type:t,children:n}=e;if(t===E.Emphasis||t===E.StrongEmphasis||t===E.Strikethrough)return[n[0].to,n.at(-1).from];if(t===E.Link||t===E.Image){let e=n.find((e,t)=>t>0&&e.type===E.LinkMark);return e?[n[0].to,e.from]:null}return null}function F(e,t,n){for(let r of e){if(r.to<=t||r.from>=n||t<=r.from&&r.to<=n)continue;let i=bt(r);return i&&i[0]<=t&&n<=i[1]?F(r.children,t,n):F(e,Math.min(t,r.from),Math.max(n,r.to))}return[t,n]}function I(e,t,n){for(let r of e)if(!(r.to<=t||r.from>=n)&&(t>r.from||r.to>n))return I(e,Math.min(t,r.from),Math.max(n,r.to));return[t,n]}const L=e=>e===` `||e===` `;function xt(e,t,n){for(;t<n&&L(e[t]);)t++;for(;n>t&&L(e[n-1]);)n--;return[t,n]}function St(e,t,n,r){let i=T(w(e),e=>e.type===r.node||yt.has(e.type));for(let r=t;r<n;r++)if(!L(e[r])&&i.every(e=>!(e.from<=r&&r<e.to)))return!1;return!0}function Ct(e,t,n,r,i){let a=w(e),o=T(a,e=>e.type===r.node);return i?Et(e,o,t,n):wt(e,a,o,t,n,r)}function wt(e,t,n,r,i,a){for(let e=0;e!==i-r;){e=i-r,[r,i]=F(t,r,i);for(let e of n)e.to===r&&(r=e.from),e.from===i&&(i=e.to)}let o=[];for(let e of n)if(r<=e.from&&e.to<=i){let[t,n]=P(e);o.push({from:t.from,to:t.to,insert:``}),o.push({from:n.from,to:n.to,insert:``})}let[s,c]=Tt(e,r,i,o,a);return o.push({from:r,to:r,insert:s},{from:i,to:i,insert:c}),o}function Tt(e,t,n,r,i){if(i.node!==E.InlineCode)return[i.delim,i.delim];let a=e.slice(t,n);for(let e of[...r].sort((e,t)=>t.from-e.from))a=a.slice(0,e.from-t)+a.slice(e.to-t);let o="`".repeat(M(a)+1),s=a.startsWith("`")||a.endsWith("`")?` `:``;return[o+s,s+o]}function Et(e,t,n,r){let i=[];for(let a of t){if(a.to<=n||a.from>=r)continue;let[t,o]=P(a),s=Math.max(n,t.to),c=Math.min(r,o.from);for(s>=c&&([s,c]=[t.to,o.from]),[s,c]=I(a.children.slice(1,-1),s,c);s>t.to&&L(e[s-1]);)s--;for(;c<o.from&&L(e[c]);)c++;s>t.to?i.push({from:s,to:s,insert:e.slice(o.from,o.to)}):i.push({from:t.from,to:t.to,insert:``}),c<o.from?i.push({from:c,to:c,insert:e.slice(t.from,t.to)}):i.push({from:o.from,to:o.to,insert:``})}return i}function Dt(e,t,n){let{delim:r}=n,i=r.length;if(e.slice(t-i,t)===r&&e.startsWith(r,t)&&e[t-i-1]!==r[0]&&e[t+i]!==r[0])return{kind:`unwrap`,from:t-i,to:t+i};let a=w(e),o=T(a,e=>e.type===n.node).findLast(e=>e.from<=t&&t<=e.to);if(o){let[e,n]=P(o);return{kind:`move`,pos:t===o.from?e.to:t===o.to?n.from:o.to}}return R(a,t)||e[t-1]===r[0]||e[t]===r[0]?null:{kind:`insert`,pos:t}}function R(e,t){for(let n of e)if(n.from<t&&t<n.to){let e=bt(n);return!e||t<e[0]||t>e[1]?!0:R(n.children,t)}return!1}function z(e){return(t,n)=>{if(t.selection.empty)return Ot(e,t,n);let{from:r,to:i,anchor:a,head:o}=t.selection,s=[];t.doc.nodesBetween(r,i,(t,n)=>{if(t.type.spec.code)return!1;if(!t.isTextblock)return!0;let a=t.textContent,o=n+1,[c,l]=xt(a,Math.max(r-o,0),Math.min(i-o,a.length));return c<l&&s.push({text:a,base:o,from:c,to:l,active:St(a,c,l,e)}),!1});let c=s.length>0&&s.every(e=>e.active),l=s.filter(e=>c||!e.active).flatMap(t=>Ct(t.text,t.from,t.to,e,c).map(e=>({from:e.from+t.base,to:e.to+t.base,insert:e.insert})));if(l.length===0)return!1;if(n){let e=t.tr;l.sort((e,t)=>t.from-e.from||t.to-e.to);for(let t of l)t.insert?e.insertText(t.insert,t.from,t.to):e.delete(t.from,t.to);e.setSelection(g.create(e.doc,e.mapping.map(a,a<=o?1:-1),e.mapping.map(o,o<a?1:-1))),n(e.scrollIntoView())}return!0}}function Ot(e,t,n){let{$from:r}=t.selection,i=r.parent;if(!i.isTextblock||i.type.spec.code)return!1;let a=Dt(i.textContent,r.parentOffset,e);if(!a)return!1;if(n){let i=r.start(),o=t.tr;a.kind===`unwrap`&&o.delete(i+a.from,i+a.to),a.kind===`move`&&o.setSelection(g.create(o.doc,i+a.pos)),a.kind===`insert`&&(o.insertText(e.delim+e.delim,i+a.pos),o.setSelection(g.create(o.doc,i+a.pos+e.delim.length))),n(o.scrollIntoView())}return!0}function kt(){return i({toggleEm:()=>z(N.em),toggleStrong:()=>z(N.strong),toggleCode:()=>z(N.code),toggleDel:()=>z(N.del)})}function At(){return o({"Mod-b":z(N.strong),"Mod-i":z(N.em),"Mod-e":z(N.code),"Mod-Shift-x":z(N.del)})}function jt(){return f(kt(),At())}function Mt(){return f(je(),Ae(),Ee(),ke(),c(Me()),De(),Oe())}function Nt(){return f(fe(),se(),pe(),ie(),ue(),Ve(),Mt(),ae(),le(),vt(),Re(),ct(),jt(),r(),n(),a(),ce(),me(),de())}function B(){return Nt()}const Pt=new Set([`mdStrong`,`mdEm`,`mdCode`,`mdDel`,`mdLinkText`,`mdLinkUri`,`mdWikilink`]),Ft=new Set([`mdMark`,`mdLinkUri`]),It=new Set([`mdMark`,`mdLinkUri`]),V=new Set([`mdLinkText`,`mdLinkUri`]),Lt=new Set([`mdStrong`,`mdEm`,`mdCode`,`mdDel`,`mdWikilink`]);function Rt(e){return new m({key:new h(`mark-mode`),props:{attributes:{"data-mark-mode":e},decorations:e===`focus`?e=>Vt(e):void 0,clipboardTextSerializer:e===`show`?void 0:Bt}})}function zt(e){return c(Rt(e))}function Bt(e){let t=[];return e.content.forEach(e=>{let n=[];e.descendants(e=>!e.isText||!e.text?!0:(e.marks.some(e=>It.has(e.type.name))||n.push(e.text),!1)),t.push(n.join(``))}),t.join(`
2
+ `)}function Vt(e){let{$anchor:t,empty:n}=e.selection;if(!n)return y.empty;let r=t.parent;if(!r.isTextblock)return null;let i=t.start(),a=t.parentOffset,o=Ht(r,a);if(o.size===0)return y.empty;let s=[],c=new Set,l=!1;for(let e of o)if(V.has(e)){if(l)continue;l=!0,Wt(r,i,a,s,c)}else Ut(r,i,e,a,s,c);let u=s.map(([e,t])=>Ne.inline(e,t,{class:`show`}));return y.create(e.doc,u)}function Ht(e,t){let n=new Set,r=0;return e.forEach(e=>{let i=r+e.nodeSize;if(t>=r&&t<=i)for(let t of e.marks){let e=t.type.name;Pt.has(e)&&n.add(e)}r=i}),n}function Ut(e,t,n,r,i,a){let o=t,s=0,c=-1,l=-1;e.forEach(u=>{let d=u.marks.some(e=>e.type.name===n);d&&c===-1&&(c=o,l=s),!d&&c!==-1&&(r>=l&&r<=s&&U(e,t,c,o,i,a),c=-1,l=-1),o+=u.nodeSize,s+=u.nodeSize}),c!==-1&&r>=l&&r<=s&&U(e,t,c,o,i,a)}function Wt(e,t,n,r,i){let a=e.childCount;if(a===0)return;let o=-1,s=0;for(let t=0;t<a;t++){let r=e.child(t),i=s+r.nodeSize;if(n>=s&&n<=i&&r.marks.some(e=>V.has(e.type.name))){o=t;break}s=i}if(o===-1)return;let c=o;for(;c>0&&H(e.child(c-1));)c--;let l=o;for(;l<a-1&&H(e.child(l+1));)l++;let u=t;for(let t=0;t<c;t++)u+=e.child(t).nodeSize;let d=u;for(let t=c;t<=l;t++)d+=e.child(t).nodeSize;U(e,t,u,d,r,i)}function H(e){let t=!1,n=!1,r=!1;for(let i of e.marks){let e=i.type.name;e===`mdMark`?t=!0:V.has(e)?n=!0:Lt.has(e)&&(r=!0)}return!!(n||t&&!r)}function U(e,t,n,r,i,a){let o=t;e.forEach(e=>{let t=o,s=o+e.nodeSize;if(t>=n&&s<=r)for(let n of e.marks){let e=n.type.name;if(Ft.has(e)){let e=`${t}_${s}`;a.has(e)||(a.add(e),i.push([t,s]));break}}o=s})}const Gt=new h(`meowdown-wikilink-click`);function Kt(e,t){let n=l(e.schema,`mdWikilink`),r=e.doc.resolve(t),i=r.parent;if(!i.isTextblock||i.type.spec.code)return;let a=r.start(),o=-1,s=-1,c,u=0;if(i.forEach(e=>{let r=a+u;u+=e.nodeSize;let i=a+u;n.isInSet(e.marks)?(o<0&&(o=r),s=i):(o>=0&&o<=t&&t<=s&&(c={from:o,to:s}),o=-1)}),o>=0&&o<=t&&t<=s&&(c={from:o,to:s}),c)return{from:c.from,to:c.to,target:qt(e.doc.textBetween(c.from,c.to))}}function qt(e){let t=e.replace(/^\[\[/u,``).replace(/\]\]$/u,``),n=t.indexOf(`|`);return(n>=0?t.slice(0,n):t).trim()}function Jt(e){let t;return c(new m({key:Gt,props:{handleDOMEvents:{mousedown:e=>{let{from:n,to:r,empty:i}=e.state.selection;return t={from:n,to:r,empty:i},!1}},handleClick:(n,r,i)=>{if(!i.target?.closest?.(`.md-wikilink`))return!1;let a=Kt(n.state,r);return!a||!(u?i.metaKey:i.ctrlKey)&&t?.empty&&t.from>=a.from&&t.to<=a.to?!1:(e({target:a.target,event:i}),!0)}}}))}function Yt(e){let t=[],n=T(w(e),e=>e.type===E.Image);for(let r of n){let n=r.children.find(e=>e.type===E.URL),i=r.children.filter(e=>e.type===E.LinkMark);!n||i.length<2||t.push({from:r.from,to:r.to,alt:e.slice(i[0].to,i[1].from),src:e.slice(n.from,n.to)})}return t}const W=new h(`meowdown-images`);function Xt(e){let t=[];return e.doc.descendants((e,n)=>{if(e.type.spec.code)return!1;if(!e.isTextblock)return!0;if(e.childCount===0)return!1;let r=!0;if(e.forEach(e=>{e.isText||(r=!1)}),!r)return!1;for(let r of Yt(e.textContent))t.push({widgetAt:n+e.nodeSize-1,alt:r.alt,src:r.src});return!1}),t}function G(e,t){let n=[];for(let r of Xt(e)){let e=t.resolveImageUrl(r.src);e&&n.push(Ne.widget(r.widgetAt,()=>{let t=document.createElement(`div`);t.className=`md-image`,t.contentEditable=`false`;let n=document.createElement(`img`);return n.src=e,n.alt=r.alt,n.draggable=!1,t.appendChild(n),t},{key:`md-image:${e}`,side:1}))}return y.create(e.doc,n)}function Zt(e){return new m({key:W,state:{init:(t,n)=>G(n,e),apply:(t,n,r,i)=>t.docChanged?G(i,e):n},props:{decorations:e=>W.getState(e)}})}function K(e){return e?Array.from(e.files).filter(e=>e.type.startsWith(`image/`)):[]}const Qt=e=>{console.error(`[meowdown] failed to save pasted image:`,e)};async function q(e,t,n,r=Qt,i){let a=i;for(let i of t){let t;try{t=await n(i)}catch(e){r(e,i);continue}if(!t||e.isDestroyed)continue;let o=`![](${t})`,s=a==null?e.state.tr.insertText(o):e.state.tr.insertText(o,a);e.dispatch(s),a!=null&&(a+=o.length)}}function $t(e){return new m({props:{handlePaste:(t,n)=>{let r=K(n.clipboardData),{onImagePaste:i,onImageSaveError:a}=e;return r.length===0||!i?!1:(q(t,r,i,a),!0)},handleDrop:(t,n)=>{let r=K(n.dataTransfer),{onImagePaste:i,onImageSaveError:a}=e;return r.length===0||!i?!1:(q(t,r,i,a,t.posAtCoords({left:n.clientX,top:n.clientY})?.pos),!0)}}})}function en(t){return f(c(Zt(t)),ne(c($t(t)),e.high))}const tn={"Mod-b":`Bold`,"Mod-i":`Italic`,"Mod-e":`Inline code`,"Mod-Shift-x":`Strikethrough`,"Mod-1":`Heading 1`,"Mod-2":`Heading 2`,"Mod-3":`Heading 3`,"Mod-4":`Heading 4`,"Mod-5":`Heading 5`,"Mod-6":`Heading 6`},nn=new Set([`MscGen`,`Xù`,`MsGenny`,`Angular Template`]),rn=p.map(e=>e.name).filter(e=>!nn.has(e)).map(e=>({label:e,value:e.toLowerCase()})).concat({label:`Plain text`,value:``}).sort((e,t)=>e.label.localeCompare(t.label));function J(e){let t=new on;return Y(e,t),t.finish()}const an=[``,`# `,`## `,`### `,`#### `,`##### `,`###### `];var on=class{constructor(){this.parts=[],this.linePrefix=``,this.pendingFirst=null,this.atLineStart=!0,this.deferredBlankPrefix=null}write(e){if(e===``)return;if(this.emitDeferredBlankLine(),this.atLineStart&&=(this.parts.push(this.pendingFirst??this.linePrefix),this.pendingFirst=null,!1),!e.includes(`
3
3
  `)){this.parts.push(e);return}let t=e.split(`
4
4
  `);for(let e=0;e<t.length;e++)e>0&&this.parts.push(`
5
5
  `,this.linePrefix),t[e]!==``&&this.parts.push(t[e])}closeBlock(){this.atLineStart||this.parts.push(`
6
6
  `),this.atLineStart=!0,this.deferredBlankPrefix=this.linePrefix}suppressBlank(){this.deferredBlankPrefix=null}withPrefix(e,t,n){let r=this.linePrefix,i=this.pendingFirst;if(this.linePrefix=r+e,t!==null){let e=i??r;this.pendingFirst=e+t}n(),this.linePrefix=r,this.pendingFirst=i}finish(){return this.parts.join(``).replace(/\s+$/,``)+`
7
7
  `}emitDeferredBlankLine(){let e=this.deferredBlankPrefix;e!==null&&(this.parts.push(e.trimEnd(),`
8
- `),this.deferredBlankPrefix=null)}};function q(e,t){switch(e.type.name){case`doc`:J(e,t);return;case`paragraph`:X(e,t),t.closeBlock();return;case`heading`:{let n=e.attrs.level;t.write(Xt[n]??`# `),X(e,t),t.closeBlock();return}case`blockquote`:t.withPrefix(`> `,`> `,()=>J(e,t)),t.closeBlock();return;case`list`:Z(e,t,Y(e));return;case`codeBlock`:$t(e,t);return;case`horizontalRule`:t.write(`---`),t.closeBlock();return;case`table`:en(e,t);return;case`text`:e.text&&t.write(e.text);return}}function J(e,t,n=!1){let r=e.childCount,i=0;for(;i<r;){let a=e.child(i);if(a.type.name!==`list`){n&&i>0&&t.suppressBlank(),q(a,t),i++;continue}let o=i+1;for(;o<r&&e.child(o).type.name===`list`;)o++;let s=Qt(e,i,o);for(let r=i;r<o;r++)(r===i?n&&i>0:s)&&t.suppressBlank(),Z(e.child(r),t,s);i=o}}function Qt(e,t,n){for(let r=t;r<n;r++)if(!Y(e.child(r)))return!1;return!0}function Y(e){let t=e.childCount;for(let n=0;n<t;n++){let t=e.child(n);if(t.type.name!==`list`&&!(t.type.name===`paragraph`&&n===0))return!1}return!0}function X(e,t){let n=e.childCount;for(let r=0;r<n;r++){let n=e.child(r);n.isText&&n.text&&t.write(n.text)}}function Z(e,t,n){let r=e.attrs,i=r.kind===`ordered`?`${r.order??1}. `:r.kind===`task`?r.checked?`- [x] `:`- [ ] `:`- `,a=` `.repeat(r.kind===`task`?2:i.length);t.withPrefix(a,i,()=>J(e,t,n)),t.closeBlock()}function $t(e,t){let n=e.attrs.language??``,r=e.textContent,i="`".repeat(k(r,2)+1);t.write(i),n&&t.write(n),t.write(`
8
+ `),this.deferredBlankPrefix=null)}};function Y(e,t){switch(e.type.name){case`doc`:X(e,t);return;case`paragraph`:cn(e,t),t.closeBlock();return;case`heading`:{let n=e.attrs.level;t.write(an[n]??`# `),cn(e,t),t.closeBlock();return}case`blockquote`:t.withPrefix(`> `,`> `,()=>X(e,t)),t.closeBlock();return;case`list`:ln(e,t,Z(e));return;case`codeBlock`:un(e,t);return;case`horizontalRule`:t.write(`---`),t.closeBlock();return;case`table`:dn(e,t);return;case`text`:e.text&&t.write(e.text);return}}function X(e,t,n=!1){let r=e.childCount,i=0;for(;i<r;){let a=e.child(i);if(a.type.name!==`list`){n&&i>0&&t.suppressBlank(),Y(a,t),i++;continue}let o=i+1;for(;o<r&&e.child(o).type.name===`list`;)o++;let s=sn(e,i,o);for(let r=i;r<o;r++)(r===i?n&&i>0:s)&&t.suppressBlank(),ln(e.child(r),t,s);i=o}}function sn(e,t,n){for(let r=t;r<n;r++)if(!Z(e.child(r)))return!1;return!0}function Z(e){let t=e.childCount;for(let n=0;n<t;n++){let t=e.child(n);if(t.type.name!==`list`&&!(t.type.name===`paragraph`&&n===0))return!1}return!0}function cn(e,t){let n=e.childCount;for(let r=0;r<n;r++){let n=e.child(r);n.isText&&n.text&&t.write(n.text)}}function ln(e,t,n){let r=e.attrs,i=r.kind===`ordered`?`${r.order??1}. `:r.kind===`task`?r.checked?`- [x] `:`- [ ] `:`- `,a=` `.repeat(r.kind===`task`?2:i.length);t.withPrefix(a,i,()=>X(e,t,n)),t.closeBlock()}function un(e,t){let n=e.attrs.language??``,r=e.textContent,i="`".repeat(M(r,2)+1);t.write(i),n&&t.write(n),t.write(`
9
9
  `),t.write(r),t.write(`
10
- `),t.write(i),t.closeBlock()}function en(e,t){let n=e.childCount;if(n===0)return;let r=[],i=0,a=-1;for(let t=0;t<n;t++){let n=e.child(t),o=[],s=!1;for(let e=0;e<n.childCount;e++){let t=n.child(e);t.type.name===`tableHeaderCell`&&(s=!0),o.push(nn(t))}s&&a<0&&(a=t),o.length>i&&(i=o.length),r.push(o)}if(i===0)return;let o=`| `+Array(i).fill(`---`).join(` | `)+` |`,s=a>=0?r[a]:Array(i).fill(``);t.write(tn(s,i)),t.write(`
10
+ `),t.write(i),t.closeBlock()}function dn(e,t){let n=e.childCount;if(n===0)return;let r=[],i=0,a=-1;for(let t=0;t<n;t++){let n=e.child(t),o=[],s=!1;for(let e=0;e<n.childCount;e++){let t=n.child(e);t.type.name===`tableHeaderCell`&&(s=!0),o.push(pn(t))}s&&a<0&&(a=t),o.length>i&&(i=o.length),r.push(o)}if(i===0)return;let o=`| `+Array(i).fill(`---`).join(` | `)+` |`,s=a>=0?r[a]:Array(i).fill(``);t.write(fn(s,i)),t.write(`
11
11
  `),t.write(o);for(let e=0;e<n;e++)e!==a&&(t.write(`
12
- `),t.write(tn(r[e],i)));t.closeBlock()}function tn(e,t){let n=`|`;for(let r=0;r<t;r++)n+=` `+(e[r]??``)+` |`;return n}function nn(e){let t=e.textContent.trim();return!t.includes(`|`)&&!t.includes(`
12
+ `),t.write(fn(r[e],i)));t.closeBlock()}function fn(e,t){let n=`|`;for(let r=0;r<t;r++)n+=` `+(e[r]??``)+` |`;return n}function pn(e){let t=e.textContent.trim();return!t.includes(`|`)&&!t.includes(`
13
13
  `)?t:t.replaceAll(`|`,String.raw`\|`).replaceAll(`
14
- `,` `)}function rn(e,t){let n=an(e,We.parse(t).cursor(),t);return e.nodes.doc(n)}function an(e,t,n){let r=[];if(!t.firstChild())return r;do r.push(...Q(e,t,n));while(t.nextSibling());return t.parent(),r}function Q(e,t,n){switch(t.type.id){case w.ATXHeading1:return[$(e,t,n,1)];case w.ATXHeading2:return[$(e,t,n,2)];case w.ATXHeading3:return[$(e,t,n,3)];case w.ATXHeading4:return[$(e,t,n,4)];case w.ATXHeading5:return[$(e,t,n,5)];case w.ATXHeading6:return[$(e,t,n,6)];case w.SetextHeading1:return[$(e,t,n,1)];case w.SetextHeading2:return[$(e,t,n,2)];case w.Paragraph:return[on(e,t,n)];case w.Blockquote:return[sn(e,t,n)];case w.BulletList:return cn(e,t,n,`bullet`,1);case w.OrderedList:return ln(e,t,n);case w.FencedCode:case w.CodeBlock:return[fn(e,t,n)];case w.HorizontalRule:return[e.nodes.horizontalRule()];case w.Table:return[pn(e,t,n)];case w.Task:return[on(e,t,n)];default:return[]}}function $(e,t,n,r){let i=t.from,a=t.to;if(t.firstChild()){t.type.id===w.HeaderMark&&(i=t.to);let e=-1,n=-1;do e=t.type.id,n=t.from;while(t.nextSibling());e===w.HeaderMark&&n>i&&(a=n),t.parent()}let o=n.slice(i,a).trim();return e.nodes.heading({level:r},o)}function on(e,t,n){let r=n.slice(t.from,t.to);return e.nodes.paragraph(r)}function sn(e,t,n){let r=[];if(t.firstChild()){do{if(t.type.id===w.QuoteMark)continue;r.push(...Q(e,t,n))}while(t.nextSibling());t.parent()}return e.nodes.blockquote(r)}function cn(e,t,n,r,i){let a=[];if(t.firstChild()){do t.type.id===w.ListItem&&a.push(un(e,t,n,r,i));while(t.nextSibling());t.parent()}return a}function ln(e,t,n){let r=1;if(t.firstChild()){if(t.type.id===w.ListItem&&t.firstChild()){if(t.type.id===w.ListMark){let e=n.slice(t.from,t.to),i=Number.parseInt(e,10);Number.isFinite(i)&&(r=i)}t.parent()}t.parent()}return cn(e,t,n,`ordered`,r)}function un(e,t,n,r,i){let a=[],o=null;if(t.firstChild()){do{if(t.type.id===w.ListMark)continue;if(r===`bullet`&&t.type.id===w.Task){let r=dn(e,t,n);o=r.checked,a.push(r.paragraph);continue}a.push(...Q(e,t,n))}while(t.nextSibling());t.parent()}return e.nodes.list({kind:o===null?r:`task`,order:r===`ordered`?i:null,checked:o??!1,collapsed:!1},a)}function dn(e,t,n){let r=!1,i=t.from,a=t.to;t.firstChild()&&(t.type.id===w.TaskMarker&&(r=n.slice(t.from,t.to).toLowerCase().includes(`x`),i=t.to),t.parent());let o=n.slice(i,a);return o.startsWith(` `)&&(o=o.slice(1)),{checked:r,paragraph:o===``?e.nodes.paragraph():e.nodes.paragraph(o)}}function fn(e,t,n){let r=``,i=``;if(t.firstChild()){do switch(t.type.id){case w.CodeInfo:r=n.slice(t.from,t.to);break;case w.CodeText:i=n.slice(t.from,t.to);break}while(t.nextSibling());t.parent()}return e.nodes.codeBlock({language:r},i)}function pn(e,t,n){let r=[];if(t.firstChild()){do{let i=t.type.id;i===w.TableHeader?r.push(mn(e,t,n,!0)):i===w.TableRow&&r.push(mn(e,t,n,!1))}while(t.nextSibling());t.parent()}return e.nodes.table(r)}function mn(e,t,n,r){let i=[];if(t.firstChild()){do if(t.type.id===w.TableCell){let a=n.slice(t.from,t.to).trim(),o=e.nodes.paragraph(a);i.push(r?e.nodes.tableHeaderCell(o):e.nodes.tableCell(o))}while(t.nextSibling());t.parent()}return e.nodes.tableRow(i)}let hn;function gn(){return hn??=e({extension:R()}),hn}function _n(e){return e.replace(/\n+$/u,``)}function vn(e){return e.split(`
15
- `).filter(e=>e.trim()!==``)}function yn(e){let t=K(rn(gn(),e));if(_n(t)===_n(e))return`exact`;let n=vn(e),r=vn(t);return n.length===r.length&&n.every((e,t)=>e===r[t])?`normalizing`:`lossy`}export{qt as EDITOR_KEY_BINDINGS,yn as checkRoundTrip,Yt as codeBlockLanguages,R as defineEditorExtension,Kt as defineImages,jt as defineMarkMode,ke as definePlaceholder,Ae as defineReadonly,Bt as defineWikilinkClickHandler,K as docToMarkdown,rn as markdownToDoc};
14
+ `,` `)}function mn(e,t){let n=hn(e,Xe.parse(t).cursor(),t);return e.nodes.doc(n)}function hn(e,t,n){let r=[];if(!t.firstChild())return r;do r.push(...Q(e,t,n));while(t.nextSibling());return t.parent(),r}function Q(e,t,n){switch(t.type.id){case E.ATXHeading1:return[$(e,t,n,1)];case E.ATXHeading2:return[$(e,t,n,2)];case E.ATXHeading3:return[$(e,t,n,3)];case E.ATXHeading4:return[$(e,t,n,4)];case E.ATXHeading5:return[$(e,t,n,5)];case E.ATXHeading6:return[$(e,t,n,6)];case E.SetextHeading1:return[$(e,t,n,1)];case E.SetextHeading2:return[$(e,t,n,2)];case E.Paragraph:return[gn(e,t,n)];case E.Blockquote:return[_n(e,t,n)];case E.BulletList:return vn(e,t,n,`bullet`,1);case E.OrderedList:return yn(e,t,n);case E.FencedCode:case E.CodeBlock:return[Sn(e,t,n)];case E.HorizontalRule:return[e.nodes.horizontalRule()];case E.Table:return[Cn(e,t,n)];case E.Task:return[gn(e,t,n)];default:return[]}}function $(e,t,n,r){let i=t.from,a=t.to;if(t.firstChild()){t.type.id===E.HeaderMark&&(i=t.to);let e=-1,n=-1;do e=t.type.id,n=t.from;while(t.nextSibling());e===E.HeaderMark&&n>i&&(a=n),t.parent()}let o=n.slice(i,a).trim();return e.nodes.heading({level:r},o)}function gn(e,t,n){let r=n.slice(t.from,t.to);return e.nodes.paragraph(r)}function _n(e,t,n){let r=[];if(t.firstChild()){do{if(t.type.id===E.QuoteMark)continue;r.push(...Q(e,t,n))}while(t.nextSibling());t.parent()}return e.nodes.blockquote(r)}function vn(e,t,n,r,i){let a=[];if(t.firstChild()){do t.type.id===E.ListItem&&a.push(bn(e,t,n,r,i));while(t.nextSibling());t.parent()}return a}function yn(e,t,n){let r=1;if(t.firstChild()){if(t.type.id===E.ListItem&&t.firstChild()){if(t.type.id===E.ListMark){let e=n.slice(t.from,t.to),i=Number.parseInt(e,10);Number.isFinite(i)&&(r=i)}t.parent()}t.parent()}return vn(e,t,n,`ordered`,r)}function bn(e,t,n,r,i){let a=[],o=null;if(t.firstChild()){do{if(t.type.id===E.ListMark)continue;if(r===`bullet`&&t.type.id===E.Task){let r=xn(e,t,n);o=r.checked,a.push(r.paragraph);continue}a.push(...Q(e,t,n))}while(t.nextSibling());t.parent()}return e.nodes.list({kind:o===null?r:`task`,order:r===`ordered`?i:null,checked:o??!1,collapsed:!1},a)}function xn(e,t,n){let r=!1,i=t.from,a=t.to;t.firstChild()&&(t.type.id===E.TaskMarker&&(r=n.slice(t.from,t.to).toLowerCase().includes(`x`),i=t.to),t.parent());let o=n.slice(i,a);return o.startsWith(` `)&&(o=o.slice(1)),{checked:r,paragraph:o===``?e.nodes.paragraph():e.nodes.paragraph(o)}}function Sn(e,t,n){let r=``,i=``;if(t.firstChild()){do switch(t.type.id){case E.CodeInfo:r=n.slice(t.from,t.to);break;case E.CodeText:i=n.slice(t.from,t.to);break}while(t.nextSibling());t.parent()}return e.nodes.codeBlock({language:r},i)}function Cn(e,t,n){let r=[];if(t.firstChild()){do{let i=t.type.id;i===E.TableHeader?r.push(wn(e,t,n,!0)):i===E.TableRow&&r.push(wn(e,t,n,!1))}while(t.nextSibling());t.parent()}return e.nodes.table(r)}function wn(e,t,n,r){let i=[];if(t.firstChild()){do if(t.type.id===E.TableCell){let a=n.slice(t.from,t.to).trim(),o=e.nodes.paragraph(a);i.push(r?e.nodes.tableHeaderCell(o):e.nodes.tableCell(o))}while(t.nextSibling());t.parent()}return e.nodes.tableRow(i)}let Tn;function En(){return Tn??=t({extension:B()}),Tn}function Dn(e){return e.replace(/\n+$/u,``)}function On(e){return e.split(`
15
+ `).filter(e=>e.trim()!==``)}function kn(e){let t=J(mn(En(),e));if(Dn(t)===Dn(e))return`exact`;let n=On(e),r=On(t);return n.length===r.length&&n.every((e,t)=>e===r[t])?`normalizing`:`lossy`}export{tn as EDITOR_KEY_BINDINGS,kn as checkRoundTrip,rn as codeBlockLanguages,B as defineEditorExtension,en as defineImages,zt as defineMarkMode,Pe as definePlaceholder,Fe as defineReadonly,Jt as defineWikilinkClickHandler,J as docToMarkdown,mn as markdownToDoc};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@meowdown/core",
3
3
  "type": "module",
4
- "version": "0.5.0",
4
+ "version": "0.8.0",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",